/**
 * TmCustomDaoImpl.java
 * Created at 2017-2-8
 * Created by xieshuang
 * Copyright (C) 2017 BROADTEXT SOFTWARE, All rights reserved.
 */
package com.broadtext.rms.basic.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.broadtext.common.bean.EntityPageBean;
import com.broadtext.common.exp.DaoException;
import com.broadtext.common.repository.EntityDao;
import com.broadtext.rms.basic.dao.ITmCustomDao;
import com.broadtext.rms.basic.model.TmCustom;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;

/**
 * <p>ClassName: TmCustomDaoImpl</p>
 * <p>Description: 客户dao接口实现类</p>
 * <p>Author: xieshuang</p>
 * <p>Date: 2017-2-8</p>
 */
@Repository("tmCustomDao")
public class TmCustomDaoImpl extends EntityDao<TmCustom> implements ITmCustomDao {
    /**
     * 
     * <p>Description: 获取注册客户</p>
     * @param map 查询条件
     * @param pageBounds 分页
     * @return 查血结果
     * @throws DaoException 异常
     */
    @SuppressWarnings("rawtypes")
    @Override
    public EntityPageBean findRegCustom(Map<String, Object> map, PageBounds pageBounds) throws DaoException {
        return this.findEntityPageByProperty("com.broadtext.rms.basic.model.TmCustom.findRegCustoms",
            map, pageBounds);
    }
    
    /**
     * 
     * <p>Description: 根据id获取客户对象</p>
     * @param id 主键id
     * @return 客户对象
     * @throws DaoException 异常
     */
    public TmCustom findCustomerById(String id) throws DaoException {
        TmCustom t = new TmCustom();
        List<Object> list = this.getCurrentSession()
                .selectList("com.broadtext.rms.basic.model.TmCustom.findEntityById", id);
        if(list!=null&&list.size()>0){
            t = (TmCustom)list.get(0);
        }
        return t;
    }
    
    /**
     * 
     * <p>Description: 检查待删除客户状态是否合法</p>
     * @param ids id数组
     * @return 检查结果
     * @throws DaoException 异常
     */
    public Object checkCustomerStatus(String[] ids) throws DaoException {
        String result = "true";
        List<TmCustom> cusList;
        cusList = this.getCurrentSession().selectList("com.broadtext.rms.basic.model.TmCustom.getCustomerByIds",ids);
        if(!cusList.isEmpty()){
            //只包含未使用状态返回true;
            result = "false";
        } 
        //检查是否该客户是否被厂区包含
        List<TmCustom> cusListTwo;
        cusListTwo = this.getCurrentSession().selectList("com.broadtext.rms.basic.model.TmCustom.getPlantByCusIds",ids);
        if(!cusListTwo.isEmpty()){
            //只包含未使用状态返回true;
            result = "false";
        } 
        return result;
    }
}
